<template>
  <div style="background-color: white; margin-top: -5px; min-height: 100vh">
    <van-form @submit="submitForm" readonly>
      <van-field
        v-model="form.orderName"
        label="商机名称"
        placeholder="请输入商机名称"
      />
      <van-field
        v-model="form.productName"
        label="产品名称"
        placeholder="请输入产品名称"
      />
      <van-field
        v-model="form.shippingPrice"
        label="出货价"
        placeholder="请输入出货价"
      />
      <van-field
        v-model="form.discountPrice"
        label="折扣后金额"
        placeholder="请输入折扣后金额"
      />
      <van-field
        v-model="form.discountRate"
        label="折扣率"
        placeholder="请输入折扣率"
      />
      <van-field
        v-model="form.remark"
        label="备注"
        placeholder="请输入备注"
      />
      <div class="mobile-footer">
        <van-button
          type="info"
          native-type="submit"
          style="width: 90%; border-radius: 10px"
          >办理</van-button
        >
      </div>
    </van-form>
     <auditComponent ref="auditComponent" @handle="handleBtn"></auditComponent>
  </div>
</template>
<script>
import { getDiscount, audit} from "@/api/crm/discount"
import auditComponent from "../components/auditComponent.vue";
export default {
  name: "Approve",
   components: {
    auditComponent
  },
  data() {
    return {
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 指定跳转节点
      nodeCode: "",
      customerList: [],
      orderList: [],
      value: '',
      taskId: ''
    };
  },
  created() {
    this.value = this.$route.query.value;
    this.taskId = this.$route.query.taskId;
    this.getDiscount();
  },
  methods: {
    async getDiscount() {
      await getDiscount(this.value).then((response) => {
        if (!response.data) {
          this.$modal.alertWarning("代办任务不存在");
        }
        this.form = response.data;
        this.title = this.form.createBy + " 产品折扣申请";
        this.open = true;
      });
    },
    submitForm(){
      this.$refs.auditComponent.open();
    },
    /** 审核通过按钮 */
    handleBtn(obj) {
      this.form.taskId = this.taskId;
      this.form.message = obj.message
      this.form.signature = obj.signature
      this.form.skipType = obj.skipType
      audit(this.form).then((response) => {
        this.$toast.success("办理成功");
        this.$router.replace("/flow/todo")
      }); 
    },
  },
};
</script>
<style scoped>
</style>
